package com.aptemo.webetek.server.handlers;

import java.util.Date;

import com.aptemo.webetek.client.commands.Action;
import com.aptemo.webetek.client.commands.impl.GetEventsPagingAction;
import com.aptemo.webetek.client.enums.EnumEventStatus;
import com.aptemo.webetek.client.exceptions.BackendException;
import com.aptemo.webetek.server.datastore.DataStoreAPI;
import com.aptemo.webetek.shared.EventBean;
import com.aptemo.webetek.shared.PagingResult;

public class EventsPagingHandler
		extends ActionHandler<GetEventsPagingAction, PagingResult<EventBean>>
{

	public EventsPagingHandler(DataStoreAPI dataService)
	{
		super(dataService);
	}

	public Class<? extends Action<?>> getActionType()
	{
		return GetEventsPagingAction.class;
	}

	@Override
	public PagingResult<EventBean> invoke(GetEventsPagingAction action) throws BackendException
	{

		String teamId = action.getTeamId();
		String labelId = action.getLabelId();
		Date treshold = action.getDate();
		EnumEventStatus status = action.getStatus();
		String cursor = action.getCursor();
		int pageSize = action.getPageSize();

		return dataService.getEvents(teamId, labelId, treshold, status, cursor, pageSize);
	}
}
